home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1995.rar
/
1995
/
DEC
/
DI9512AC
/
example.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-07-31
|
12KB
|
486 lines
unit Example;
interface
uses
SysUtils, Classes,
acStream, acList;
type
{ TOptions is used to store application options }
TOptions = class(TacStreamable)
private
FLogResources : Boolean;
FLogMemory : Boolean;
FLogDisk : Boolean;
protected
{ TPersistent overrides }
procedure AssignTo(Dest: TPersistent); override;
{ TEzacStreamable overrides }
procedure InitFields; override;
procedure SaveToStream(Stream: TacObjStream); override;
procedure ReadFromStream(Stream: TacObjStream); override;
public
{ Properties }
property LogResources: Boolean
read FLogResources
write FLogResources;
property LogMemory: Boolean
read FLogMemory
write FLogMemory;
property LogDisk: Boolean
read FLogDisk
write FLogDisk;
end;
{ TLogItem is the base class for log entries. }
TLogItem = class(TacStreamable)
private
FTimeStamp : TDateTime; { Time of log snapshot }
protected
{ TPersistent overrides }
procedure AssignTo(Dest: TPersistent); override;
{ TEzStreamable overrides }
procedure InitFields; override;
function GetAsString: string; override;
procedure SaveToStream(Stream: TacObjStream); override;
procedure ReadFromStream(Stream: TacObjStream); override;
public
{ Properties }
property TimeStamp: TDateTime
read FTimeStamp;
end;
{ TResourceLogItem handles resource tracking log entries. }
TResourceLogItem = class(TLogItem)
private
FSysPctFree : Word; { Percentage of free system resources }
FGdiPctFree : Word; { Percentage of free GDI resources }
FUserPctFree : Word; { Percentage of free user resources }
function GetMinimum: Word;
protected
{ TPersistent overrides }
procedure AssignTo(Dest: TPersistent); override;
{ TacStreamable overrides }
procedure InitFields; override;
function GetAsString: String; override;
procedure SaveToStream(Stream: TacObjStream); override;
procedure ReadFromStream(Stream: TacObjStream); override;
public
{ Properties }
property System: Word
read FSysPctFree;
property User: Word
read FUserPctFree;
property Gdi: Word
read FGdiPctFree;
property Minimum: Word
read GetMinimum;
end;
{ TMemoryLogItem handles memory usage log entries. }
TMemoryLogItem = class(TLogItem)
private
FFreeSpace : LongInt; { Amount of free memory (KB) }
FLargestBlock : LongInt; { Size of largest available block (KB) }
protected
{ TPersistent overrides }
procedure AssignTo(Dest: TPersistent); override;
{ TacStreamable overrides }
procedure InitFields; override;
function GetAsString: string; override;
procedure SaveToStream(Stream: TacObjStream); override;
procedure ReadFromStream(Stream: TacObjStream); override;
public
{ Properties }
property FreeSpace: LongInt
read FFreeSpace;
property LargestBlock: LongInt
read FLargestBlock;
end;
{ TDiskLogItem handles disk usage tracking log entries. }
TDiskLogItem = class(TLogItem)
private
FFreeSpace : LongInt; { Total amount fo free fixed disk space (MB) }
function GetTotalFreeDiskSpace: LongInt;
protected
{ TPersistent overrides }
procedure AssignTo(Dest: TPersistent); override;
{ TacStreamable overrides }
procedure InitFields; override;
function GetAsString: string; override;
procedure SaveToStream(Stream: TacObjStream); override;
procedure ReadFromStream(Stream: TacObjStream); override;
public
{ Properties }
property FreeSpace: LongInt
read FFreeSpace;
end;
{ TLog is the list of log entries }
TLog = class(TacObjStringList)
private
function GetLogItem(const Idx: TacObjListIndex): TLogItem;
public
{ For easier item access }
property Items[const Idx: TacObjListIndex]: TLogItem
read GetLogItem; default;
end;
{ TLogStream represents the log data file }
TSignature = String[6];
TLogStream = class(TacFileObjStream)
private
FSignature : TSignature;
protected
procedure ReadHeader; override;
procedure SaveHeader; override;
end;
implementation
uses
WinTypes, WinProcs;
const
LOG_SIGNATURE : TSignature = 'LOGDAT';
{ TOptions }
procedure TOptions.AssignTo(Dest: TPersistent);
begin
if ( (Dest is TOptions) and (Self is Dest.ClassType) ) then
begin
with Dest as TOptions do
begin
FLogResources := self.FLogResources;
FLogMemory := self.FLogMemory;
FLogDisk := self.FLogDisk;
end;
end
else
begin
inherited AssignTo(Dest);
end;
end;
procedure TOptions.InitFields;
begin
inherited InitFields;
FLogResources := False;
FLogMemory := False;
FLogDisk := False;
end;
procedure TOptions.SaveToStream(Stream: TacObjStream);
begin
Stream.SaveBuffer(FLogResources, SizeOf(FLogResources));
Stream.SaveBuffer(FLogMemory, SizeOf(FLogMemory));
Stream.SaveBuffer(FLogDisk, SizeOf(FLogDisk));
end;
procedure TOptions.ReadFromStream(Stream: TacObjStream);
begin
Stream.ReadBuffer(FLogResources, SizeOf(FLogResources));
Stream.ReadBuffer(FLogMemory, SizeOf(FLogMemory));
Stream.ReadBuffer(FLogDisk, SizeOf(FLogDisk));
end;
{ TLogItem }
procedure TLogItem.AssignTo(Dest: TPersistent);
begin
if ( (Dest is TLogItem) and (Self is Dest.ClassType) ) then
begin
with Dest as TLogItem do
begin
FTimeStamp := self.FTimeStamp;
end;
end
else
begin
inherited AssignTo(Dest);
end;
end;
procedure TLogItem.InitFields;
begin
inherited InitFields;
FTimeStamp := Now;
end;
procedure TLogItem.SaveToStream(Stream: TacObjStream);
begin
Stream.SaveBuffer(FTimeStamp, SizeOf(FTimeStamp));
end;
procedure TLogItem.ReadFromStream(Stream: TacObjStream);
begin
Stream.ReadBuffer(FTimeStamp, SizeOf(FTimeStamp));
end;
function TLogItem.GetAsString: String;
begin
Result := FormatDateTime('mm/dd/yy hh:mm:ss', TimeStamp);
end;
{ TResourceLogItem }
function TResourceLogItem.GetMinimum: Word;
begin
Result := System;
if ( GDI < Result ) then Result := GDI;
if ( User < Result ) then Result := User;
end;
procedure TResourceLogItem.AssignTo(Dest: TPersistent);
begin
if ( (Dest is TResourceLogItem) and (Self is Dest.ClassType) ) then
begin
inherited AssignTo(TLogItem(Dest));
with Dest as TResourceLogItem do
begin
FSysPctFree := self.FSysPctFree;
FGdiPctFree := self.FGdiPctFree;
FUserPctFree := self.FUserPctFree;
end;
end
else
begin
inherited AssignTo(Dest);
end;
end;
procedure TResourceLogItem.InitFields;
begin
{ Allow TLogItem to initialize }
inherited InitFields;
FSysPctFree := GetFreeSystemResources(GFSR_SystemResources);
FGdiPctFree := GetFreeSystemResources(GFSR_GDIResources);
FUserPctFree := GetFreeSystemResources(GFSR_UserResources);
end;
procedure TResourceLogItem.SaveToStream(Stream: TacObjStream);
begin
{ Allow TLogItem chance to save }
inherited SaveToStream(Stream);
Stream.SaveBuffer(FSysPctFree, SizeOf(FSysPctFree));
Stream.SaveBuffer(FGdiPctFree, SizeOf(FGdiPctFree));
Stream.SaveBuffer(FUserPctFree, SizeOf(FUserPctFree));
end;
procedure TResourceLogItem.ReadFromStream(Stream: TacObjStream);
begin
{ Allow TLogItem chance to read }
inherited ReadFromStream(Stream);
Stream.ReadBuffer(FSysPctFree, SizeOf(FSysPctFree));
Stream.ReadBuffer(FGdiPctFree, SizeOf(FGdiPctFree));
Stream.ReadBuffer(FUserPctFree, SizeOf(FUserPctFree));
end;
function TResourceLogItem.GetAsString: String;
begin
{ Get Timestamp string from TLogItem }
Result := inherited GetAsString;
{ Append resource descriptions }
AppendStr(Result, ' Rsrc